from django.db import models

# Create your models here.

from django.utils import timezone

from django.db import models


# Create your models here.

# 资讯表

class NewsInfo(models.Model):
    status_choices = (
        ('0', '待审核'),
        ('1', '不可发布'),
        ('2', '可发布')
    )
    news_status = models.CharField(verbose_name='资讯状态', max_length=1, choices=status_choices, default='0')
    news_name = models.CharField(verbose_name='资讯标题', max_length=50, default=f'{timezone.now()} + 未命名资讯', db_index=True)
    news_initiator = models.ForeignKey('user.UserInfo', verbose_name='发起者', related_name='news_initiator_id',
                                       on_delete=models.SET_NULL, null=True, db_index=True)
    news_initiator_phone = models.CharField(verbose_name='发起者联系方式', max_length=11, default='')
    news_collect_num = models.IntegerField(verbose_name='收藏人数', default=0)
    news_tag = models.CharField(verbose_name='资讯标签', max_length=30, default='')
    news_detail = models.TextField(verbose_name='资讯详情', max_length=300, default='一个志愿资讯')
    news_cover = models.FileField(verbose_name='资讯封面', upload_to='newsCover', default='')
    news_create_time = models.DateTimeField(verbose_name='创建时间', default=timezone.now)

    class Meta:
        db_table = 'newsinfo'
        verbose_name = "资讯表"
        verbose_name_plural = verbose_name

    def __str__(self):
        """将模型类以字符串的方式输出"""
        return self.news_name
